<?php

namespace App\Http\Controllers\Applet\Shop;

use App\Exceptions\ShopException;
use App\Services\Applet\Shop\ShopGoodsService;
use Exception;
use Illuminate\Http\JsonResponse;

class ShopGoodsController extends BaseShopController
{

    protected ShopGoodsService $shopGoodsService;

    /**
     * @throws Exception
     */
    public function __construct()
    {
        parent::__construct();
        $this->shopGoodsService = $this->loadService('Applet\Shop\ShopGoodsService');
    }

    /**
     * 列表
     * @return JsonResponse
     * @throws Exception
     */
    public function list(): JsonResponse
    {
        $list = $this->shopGoodsService->list($this->params);
        return outputJsonResult($list);
    }

    /**
     * 商品详情
     * @return JsonResponse
     * @throws ShopException
     */
    public function detail(): JsonResponse
    {
        $rule = [
            'id' => 'required|min:1',
        ];

        if ($this->ruleCheck($rule)) {
            return outputJsonError();
        }

        $list = $this->shopGoodsService->detail($this->params);
        return outputJsonResult($list);
    }
}
